home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 6 / MacMania 6.toast / / Multimedia & Desktop / sk8 / SK8InJava / Code / Actors / Label.java < prev    next >
Encoding:
Java Source  |  1997-02-27  |  2.1 KB  |  68 lines  |  [TEXT/CWIE]

  1. /*  SK8 © 1997 Apple Computer, Inc.
  2.     This code is protected under the current SK8 License
  3.     See http://sk8.research.apple.com/ for more information
  4.     Apple Research Laboratories
  5. */
  6.  
  7. import java.awt.*;
  8.  
  9. class label extends rectangle {
  10.     
  11.     // constructor. 
  12.     
  13.     public label() {
  14.         super();
  15.         this.settext("Untitled");
  16.         this.setfillcolor(sk8.white);
  17.         this.setframesize(0);
  18.         // this.setresizeable(false);
  19.         this.bindlabeltext();
  20.     }
  21.     
  22.     //======================================================================
  23.     // changing the text requires changing the size of it. 
  24.     //======================================================================
  25.  
  26.     public void bindlabeltext () {
  27.         Point textsize = this.actortextsize();
  28.         int framesize = this.framesize();
  29.         int width = textsize.x + framesize + 10;
  30.         int height = textsize.y + framesize + 14;
  31.         Rectangle mybounds = this.boundsrect(true);
  32.         symbol textloc = this.textlocation();
  33.         if ((textloc == sk8.quote("CENTER")) || (textloc == sk8.quote("TOPCENTER")) || (textloc == sk8.quote("BOTTOMCENTER"))) {
  34.             this.setsize(width, height, false, false);
  35.         } else if ((textloc == sk8.quote("TOPLEFT")) || (textloc == sk8.quote("CENTERLEFT")) || (textloc == sk8.quote("BOTTOMLEFT"))) {
  36.             this.setboundsrect(mybounds.x, mybounds.y, width, height, true, false, false);
  37.         } else if ((textloc == sk8.quote("TOPRIGHT")) || (textloc == sk8.quote("CENTERRIGHT")) || (textloc == sk8.quote("BOTTOMRIGHT"))) {
  38.             int newleft = mybounds.x + mybounds.width - width;
  39.             int newtop = mybounds.y + mybounds.height - height;
  40.             this.setboundsrect(newleft, newtop, newleft + width, newtop + height);
  41.         }
  42.     }
  43.  
  44.     public void settext (String thetext) {
  45.         super.settext(thetext);
  46.         this.bindlabeltext();
  47.     }
  48.  
  49.     public void settextfont (String name) {
  50.         super.settextfont(name);
  51.         this.bindlabeltext();
  52.     }
  53.  
  54.     public void settextsize (int newsize) {
  55.         super.settextsize(newsize);
  56.         this.bindlabeltext();
  57.     }
  58.  
  59.     public void settextstyle (int newstyle) {
  60.         super.settextstyle(newstyle);
  61.         this.bindlabeltext();
  62.     }
  63.  
  64.     public void setframesize (int newsize) {
  65.         super.setframesize(newsize);
  66.         this.bindlabeltext();
  67.     }
  68. }